<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class OddsHandicapCollection extends ResourceCollection
{
    public $resource;

    public function __construct($resource)
    {
        $this->resource = $resource;
        parent::__construct($resource);
    }

    public function toArray($request)
    {
        if ($this->resource->count() >= 1) {
            foreach ($this->collection as $key => $item) {
                $data[$key]['id'] = $item->id;
                $data[$key]['main_game_plat_code'] = $item->plat->main_game_plat_code ?? '';
                $data[$key]['plat_code'] = $item->plat_code;
                $data[$key]['odds_value'] = $item->odds_value;
                $data[$key]['description'] = $item->description;
                $data[$key]['updated_at'] = $item->updated_at->toDateTimeString();
                $data[$key]['created_at'] = $item->created_at->toDateTimeString();
            }
            $this->resource->setCollection(collect($data));
            return [
                $this->resource
            ];
        } else {
            return [];
        }

    }
}
